import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import '@/assets/css/allstyle.css'


Vue.use(ElementUI);
Vue.config.productionTip = false
axios.defaults.baseURL = 'http://localhost:8080'

axios.interceptors.response.use(function(response) {
    let data = response.data
    if (response.status === 444) {
        router.push('/login');
        this.$message.error('请重新登录');

    } else {
        return data;
    }

})


axios.interceptors.request.use(function(request) {
    //请求拦截器传递token
    console.log(request.url);
    const token = localStorage.getItem("token");
    if (token) {
        request.headers["Authorization"] = token;
    }
    return request;
}, function(err) {
    return Promise.reject(err);
})

Vue.prototype.$http = axios

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')